//
//  HNSH_SignADCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/4/22.
//

#import "HNSH_SignADCell.h"

@interface HNSH_SignADCell ()

/* bgView */
@property (nonatomic, strong) UIView *bgView;
/* imgV */
@property (nonatomic, strong) UIImageView *imgV;
/* titleLabel */
@property (nonatomic, strong) UILabel *titleLabel;
/* button */
@property (nonatomic, strong) UIButton *button;

/* jfIcon */
@property (nonatomic, strong) UIImageView *jfIcon;
/* jfLabel */
@property (nonatomic, strong) UILabel *jfLabel;
/* jfBgView */
@property (nonatomic, strong) UIView *jfBgView;

/* lineView */
@property (nonatomic, strong) UIView *lineView;
//huibao_pledge_agreement
@end

@implementation HNSH_SignADCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}

- (void)setModel:(HNSH_AdvertListItem *)model {
    [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:[UIImage imageNamed:@"sheng_sign_icon_video"]];
    self.titleLabel.text = [NSString stringWithFormat:@"%@ ",model.name];
//    self.titleLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.titleLabel.text SelectContent:model.desc_text CommonFont:self.titleLabel.font SpeFont:self.titleLabel.font Color:[UIColor colorWithHexString:@"#F73525"]];
    self.jfLabel.text = model.desc_text;
    [self.button setTitle:model.daily_count <= model.complete_count ? @"已完成" : @"去完成" forState:UIControlStateNormal];
    if (model.daily_count <= model.complete_count) {
        self.button.layer.borderColor = [[UIColor appGrayLabelColor] CGColor];
        [self.button setTitleColor:[UIColor appGrayLabelColor] forState:UIControlStateNormal];
    } else {
        self.button.layer.borderColor = [[UIColor appGreenColor] CGColor];
        [self.button setTitleColor:[UIColor appGreenColor] forState:UIControlStateNormal];
    }
    
}

- (void)addAllViews {
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.bgView];
    
    [self.bgView addSubview:self.imgV];
    [self.bgView addSubview:self.titleLabel];
    [self.bgView addSubview:self.button];
    
    [self.bgView addSubview:self.jfBgView];
    [self.bgView addSubview:self.jfLabel];
    [self.bgView addSubview:self.jfIcon];
    
    [self.bgView addSubview:self.lineView];
}

- (void)addAllLayout {
    [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.mas_equalTo(16);
        make.width.mas_equalTo(24);
        make.height.mas_equalTo(20);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.mas_equalTo(47);
        make.height.mas_equalTo(22);
    }];
    
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(24);
        make.width.mas_equalTo(66);
    }];
    
    [self.jfLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.mas_equalTo(128);
        make.height.mas_equalTo(20);
    }];
    [self.jfBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.mas_equalTo(110);
        make.height.mas_equalTo(20);
        make.right.equalTo(self.jfLabel.mas_right).offset(10);
    }];
    [self.jfIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.mas_equalTo(98);
        make.height.mas_equalTo(21);
        make.width.mas_equalTo(32);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    self.titleLabel.text = @"看视频";
    self.jfLabel.text = @"+10汇豆";
}

#pragma mark lazy
-(UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]initWithFrame:CGRectMake(20, 0, kScreenWidth-40, 54)];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UIImageView *)imgV {
    if (!_imgV) {
        _imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mine_sign_ad_icon"]];
        
    }
    return _imgV;
}

- (UILabel *)titleLabel {
    if (!_titleLabel ) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = [UIColor appBlack333LabelColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _titleLabel;
}

- (UIButton *)button {
    if (!_button) {
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        [_button setTitle:@"去完成" forState:UIControlStateNormal];
        [_button setTitleColor:[UIColor appGreenColor] forState:UIControlStateNormal];
        _button.titleLabel.font = [UIFont systemFontOfSize:11];
        _button.layer.cornerRadius = 11.0f;
        _button.layer.masksToBounds = YES;
        _button.layer.borderColor = [[UIColor appGreenColor] CGColor];
        _button.layer.borderWidth = 1.0f;
        _button.userInteractionEnabled = NO;
    }
    return _button;
}

- (UIImageView *)jfIcon {
    if (!_jfIcon) {
        _jfIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mine_sign_ad_jf_icon"]];
    }
    return _jfIcon;
}

- (UILabel *)jfLabel {
    if (!_jfLabel ) {
        _jfLabel = [[UILabel alloc]init];
        _jfLabel.textColor = [UIColor colorWithHexString:@"#F45857"];
        _jfLabel.font = [UIFont systemFontOfSize:10];
    }
    return _jfLabel;
}

- (UIView *)jfBgView {
    if (!_jfBgView) {
        _jfBgView = [[UIView alloc]init];
        _jfBgView.backgroundColor = [UIColor colorWithHexString:@"#F7E9C6"];
        _jfBgView.layer.cornerRadius = 10.0f;
        _jfBgView.layer.masksToBounds = YES;
    }
    return _jfBgView;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
    }
    return _lineView;
}

@end
